package com.shopping.userside.goods.controller;

import com.shopping.entity.Result;
import com.shopping.entity.StatusCode;
import com.shopping.userside.goods.pojo.Goods;
import com.shopping.userside.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * (Goods)表控制层
 *
 * @author xusai
 * @since 2020-06-02 10:50:32
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    /**
     * 服务对象
     */
    @Autowired
    private GoodsService goodsService;

    /**
     * 查询所有数据
     *
     * @param
     * @return 所有数据
     */
    @GetMapping("/findAll")
    public Result findAll() {
      List<Goods> goodsList =goodsService.queryAll();
      if (goodsList!=null&&goodsList.size()>0){
          return new Result(true,20000,"查询成功",goodsList);
      }
      return new Result(false,20001,"查询失败");
    }

    @GetMapping("/searchGoods")
    public Result<List<Goods>> search(@RequestParam Map searchGoodsMap){
        List<Goods> list = goodsService.list(searchGoodsMap);
        if (list!=null&&list.size()>0){
        return new Result<>(true, StatusCode.OK,"查询成功",list);
    }
        return new Result<>(false, StatusCode.ERROR,"查询失败");
    }

}